// 子网掩码地址
package main

import (
    "os"
    "fmt"
    "net"
)

func main() {
    if len(os.Args) != 2 {
        fmt.Fprintf(os.Stderr, "Usage: %s is.addr\n",os.Args[0])
        os.Exit(1)
    }

    dotaddr := os.Args[1]
    addr := net.ParseIP(dotaddr)
    if addr == nil {
        fmt.Println("Invalid address")
    }
    mask := addr.DefaultMask()
    fmt.Println("Subnet mask is:", mask.String())
    network := addr.Mask(mask)
    fmt.Println("Network address is:", network.String())
    ones,bits := mask.Size()
    fmt.Println("Mask bits:", ones, "Total bits:", bits)
    os.Exit(0)
}
